Suggest adding flags to filter the package in the error message
authorSondre Lefsaker <sondrele@stud.ntnu.no>
Wed, 6 May 2015 10:08:43 +0000 (12:08 +0200)
committerSondre Lefsaker <sondrele@stud.ntnu.no>
Wed, 6 May 2015 10:08:43 +0000 (12:08 +0200)
src/cargo/ops/cargo_compile.rs
tests/test_cargo_rustc.rs

index f49a1fb347d12a53ac22ae0b8499beba0efff930..f2b276cf7ee1b1716c535f1f0a14492a133967ba 100644 (file)
@@ -168,16 +168,16 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
     let targets = try!(generate_targets(to_build, mode, filter, release));
 
     let target_with_args = match *target_rustc_args {
-        Some(args) => {
-            if targets.len() > 1 {
-                return Err(human("extra arguments to `rustc` can only be \
-                                  invoked for one target"))
-            }
+        Some(args) if targets.len() == 1 => {
             let (target, profile) = targets[0];
             let mut profile = profile.clone();
             profile.rustc_args = Some(args.to_vec());
             Some((target, profile))
-        },
+        }
+        Some(_) =>
+            return Err(human("extra arguments to `rustc` can only be passed to one target, \
+                              consider filtering\nthe package by passing e.g. `--lib` or \
+                              `--bin NAME` to specify a single target")),
         None => None,
     };
 
index 3729558c9cf850c1d4a33d1c22c1ea5535cfc782..8000517932c168dfceec628ea1259b2d7fa2dae5 100644 (file)
@@ -6,6 +6,11 @@ use hamcrest::{assert_that};
 fn setup() {
 }
 
+fn cargo_rustc_error() -> &'static str {
+    "extra arguments to `rustc` can only be passed to one target, consider filtering\n\
+    the package by passing e.g. `--lib` or `--bin NAME` to specify a single target"
+}
+
 test!(build_lib_for_foo {
     let p = project("foo")
         .file("Cargo.toml", r#"
@@ -118,7 +123,7 @@ test!(fails_when_trying_to_build_main_and_lib_with_args {
                 .arg("--").arg("-Z").arg("unstable-options"),
                 execs()
                 .with_status(101)
-                .with_stderr("extra arguments to `rustc` can only be invoked for one target"));
+                .with_stderr(cargo_rustc_error()));
 });
 
 test!(build_with_args_to_one_of_multiple_binaries {
@@ -178,7 +183,7 @@ test!(fails_with_args_to_all_binaries {
                 .arg("--").arg("-Z").arg("unstable-options"),
                 execs()
                 .with_status(101)
-                .with_stderr("extra arguments to `rustc` can only be invoked for one target"));
+                .with_stderr(cargo_rustc_error()));
 });
 
 test!(build_with_args_to_one_of_multiple_tests {